<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()
const showRules = ref(false)

function goToLobby() {
  router.push('/lobby')
}
</script>

<template>
  <div class="home-view">
    <div class="hero-section">
      <div class="hero-content">
        <h1 class="hero-title">🎨 涂色抢地盘游戏</h1>
        <p class="hero-subtitle">
          一个简单有趣的多人实时涂色游戏，通过涂色来占领画布区域，最终占领面积最大的玩家获胜！
        </p>
        <div class="hero-actions">
          <button @click="goToLobby" class="cta-button primary">
            🚀 开始游戏
          </button>
          <button @click="showRules = true" class="cta-button secondary">
            📖 游戏规则
          </button>
        </div>
      </div>
      
      <div class="hero-image">
        <div class="game-preview">
          <div class="canvas-preview">
            <div class="paint-dots">
              <div class="dot red"></div>
              <div class="dot blue"></div>
              <div class="dot green"></div>
              <div class="dot yellow"></div>
            </div>
          </div>
        </div>
      </div>
    </div>
    
    <div class="how-to-play-section">
      <h2 class="section-title">🎯 如何开始</h2>
      <div class="steps-grid">
        <div class="step-card">
          <div class="step-number">1</div>
          <h3>创建房间</h3>
          <p>设置房间名称、最大玩家数和游戏时长</p>
        </div>
        <div class="step-card">
          <div class="step-number">2</div>
          <h3>邀请朋友</h3>
          <p>分享房间码，让朋友加入你的游戏</p>
        </div>
        <div class="step-card">
          <div class="step-number">3</div>
          <h3>准备就绪</h3>
          <p>所有玩家准备完毕后，房主可以开始游戏</p>
        </div>
        <div class="step-card">
          <div class="step-number">4</div>
          <h3>开始涂色</h3>
          <p>在画布上涂色占领区域，争夺最大面积</p>
        </div>
      </div>
    </div>
    
    <!-- 游戏规则弹窗 -->
    <div v-if="showRules" class="modal-overlay" @click="showRules = false">
      <div class="modal-content rules-modal" @click.stop>
        <div class="modal-header">
          <h2>📖 游戏规则</h2>
          <button @click="showRules = false" class="close-btn">×</button>
        </div>
        
        <div class="rules-content">
          <div class="rule-section">
            <h3>🎯 游戏目标</h3>
            <p>在限定时间内，通过涂色占领画布区域，最终占领面积最大的玩家获胜。</p>
          </div>
          
          <div class="rule-section">
            <h3>🎨 涂色规则</h3>
            <ul>
              <li>每位玩家有专属颜色，不能覆盖其他玩家的颜色</li>
              <li>使用鼠标或触摸在画布上涂色</li>
              <li>可以调整画笔大小和颜色</li>
              <li>支持撤销操作，但会消耗时间</li>
            </ul>
          </div>
          
          <div class="rule-section">
            <h3>⏰ 时间限制</h3>
            <ul>
              <li>游戏时长：3-5分钟（可自定义）</li>
              <li>时间结束后自动计算各玩家占领面积</li>
              <li>占领面积最大的玩家获胜</li>
            </ul>
          </div>
          
          <div class="rule-section">
            <h3>🏆 胜负判定</h3>
            <ul>
              <li>系统自动计算每个颜色占据的像素数量</li>
              <li>面积最大的玩家获胜</li>
              <li>如果面积相同，则共享胜利</li>
            </ul>
          </div>
          
          <div class="rule-section">
            <h3>🚫 禁止行为</h3>
            <ul>
              <li>使用自动化工具或脚本</li>
              <li>恶意破坏其他玩家的涂色</li>
              <li>利用游戏漏洞获得不公平优势</li>
            </ul>
          </div>
        </div>
        
        <div class="modal-footer">
          <button @click="showRules = false" class="close-modal-btn">
            知道了
          </button>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.home-view {
  min-height: 100vh;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
}

.hero-section {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4rem;
  align-items: center;
  padding: 4rem 2rem;
  max-width: 1200px;
  margin: 0 auto;
}

.hero-content {
  text-align: left;
}

.hero-title {
  font-size: 3.5rem;
  font-weight: bold;
  color: #333;
  margin: 0 0 1.5rem 0;
  line-height: 1.2;
}

.hero-subtitle {
  font-size: 1.3rem;
  color: #666;
  margin: 0 0 2.5rem 0;
  line-height: 1.6;
}

.hero-actions {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.cta-button {
  padding: 1rem 2rem;
  border: none;
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  min-width: 160px;
}

.cta-button.primary {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
}

.cta-button.secondary {
  background: white;
  color: #667eea;
  border: 2px solid #667eea;
}

.cta-button:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.hero-image {
  display: flex;
  justify-content: center;
  align-items: center;
}

.game-preview {
  width: 400px;
  height: 300px;
  background: white;
  border-radius: 16px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.canvas-preview {
  width: 320px;
  height: 240px;
  background: #f8f9fa;
  border-radius: 8px;
  position: relative;
}

.paint-dots {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

.dot {
  position: absolute;
  border-radius: 50%;
  animation: float 3s ease-in-out infinite;
}

.dot.red {
  width: 20px;
  height: 20px;
  background: #FF6B6B;
  top: 20%;
  left: 20%;
  animation-delay: 0s;
}

.dot.blue {
  width: 16px;
  height: 16px;
  background: #4ECDC4;
  top: 60%;
  left: 70%;
  animation-delay: 1s;
}

.dot.green {
  width: 24px;
  height: 24px;
  background: #45B7D1;
  top: 70%;
  left: 30%;
  animation-delay: 2s;
}

.dot.yellow {
  width: 18px;
  height: 18px;
  background: #FFEAA7;
  top: 30%;
  left: 60%;
  animation-delay: 1.5s;
}

@keyframes float {
  0%, 100% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-10px);
  }
}

.section-title {
  text-align: center;
  font-size: 2.5rem;
  font-weight: bold;
  color: #333;
  margin: 0 0 3rem 0;
}

.how-to-play-section {
  padding: 4rem 2rem;
  background: #f8f9fa;
}

.steps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 2rem;
  max-width: 1200px;
  margin: 0 auto;
}

.step-card {
  text-align: center;
  padding: 2rem;
  background: white;
  border-radius: 16px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
  transition: all 0.3s ease;
}

.step-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
}

.step-number {
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: bold;
  margin: 0 auto 1.5rem;
}

.step-card h3 {
  font-size: 1.2rem;
  font-weight: 600;
  color: #333;
  margin: 0 0 1rem 0;
}

.step-card p {
  color: #666;
  line-height: 1.6;
  margin: 0;
}



/* 规则弹窗 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content.rules-modal {
  background: white;
  border-radius: 16px;
  max-width: 700px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 2rem 2rem 1rem;
  border-bottom: 1px solid #e9ecef;
}

.modal-header h2 {
  margin: 0;
  color: #333;
  font-size: 1.8rem;
}

.close-btn {
  background: none;
  border: none;
  font-size: 2rem;
  cursor: pointer;
  color: #666;
  padding: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.3s ease;
}

.close-btn:hover {
  background: #f8f9fa;
  color: #333;
}

.rules-content {
  padding: 2rem;
}

.rule-section {
  margin-bottom: 2rem;
}

.rule-section:last-child {
  margin-bottom: 0;
}

.rule-section h3 {
  color: #333;
  font-size: 1.3rem;
  margin: 0 0 1rem 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.rule-section p {
  color: #666;
  line-height: 1.6;
  margin: 0;
}

.rule-section ul {
  color: #666;
  line-height: 1.6;
  margin: 0;
  padding-left: 1.5rem;
}

.rule-section li {
  margin-bottom: 0.5rem;
}

.modal-footer {
  padding: 1rem 2rem 2rem;
  text-align: center;
  border-top: 1px solid #e9ecef;
}

.close-modal-btn {
  padding: 0.75rem 2rem;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.close-modal-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

@media (max-width: 992px) {
  .hero-section {
    grid-template-columns: 1fr;
    text-align: center;
    gap: 2rem;
  }
  
  .hero-content {
    text-align: center;
  }
  
  .hero-title {
    font-size: 2.5rem;
  }
  
  .hero-actions {
    justify-content: center;
  }
  
  .game-preview {
    width: 300px;
    height: 225px;
  }
  
  .canvas-preview {
    width: 240px;
    height: 180px;
  }
}

@media (max-width: 768px) {
  .hero-section {
    padding: 2rem 1rem;
  }
  
  .hero-title {
    font-size: 2rem;
  }
  
  .hero-subtitle {
    font-size: 1.1rem;
  }
  
  .cta-button {
    min-width: 140px;
    padding: 0.875rem 1.5rem;
  }
  
  .features-section,
  .how-to-play-section,
  .stats-section {
    padding: 2rem 1rem;
  }
  
  .section-title {
    font-size: 2rem;
  }
  
  .features-grid,
  .steps-grid,
  .stats-grid {
    gap: 1.5rem;
  }
  
  .modal-content.rules-modal {
    width: 95%;
  }
  
  .modal-header,
  .rules-content,
  .modal-footer {
    padding: 1.5rem;
  }
}
</style>
